package com.dao;

import com.bean.BookPage;
import com.bean.BookType;
import com.utils.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @ClassName BookTypeDao
 * @Desc 图书类型数据封装层
 * @Author xiaoding
 * @Date 2021/1/13 18:36
 * @Version 1.0
 */

public class BookTypeDao {
    private MyBatisUtils myBatisUtils = new MyBatisUtils();

    /*
     * @Author bookTypeSelect
     * @Description 返回所有图形类型
     * @Date 18:38 2021/1/13
     * @Param bookPage
     * @return java.util.List<com.bean.BookType>
     */
    public List<BookType> bookTypeSelect(BookPage bookPage) {
        SqlSession session = myBatisUtils.getSqlSession();
        String sql = "com.resources.bookTypeMapping.bookTypeSelect";
        List<BookType> list = session.selectList(sql,bookPage);
        return list;
    }

    /*
     * @Author bookTypeSelect2
     * @Description 无参查询所有图书分类数据
     * @Date 20:50 2021/1/18
     * @Param
     * @return java.util.List<com.bean.BookType>
     */
    public  List<BookType> bookTypeSelect2() {
        SqlSession session = myBatisUtils.getSqlSession();
        String sql = "com.resources.bookTypeMapping.bookTypeSelect2";
        List<BookType> list = session.selectList(sql);
        return list;
    }

    /*
     * @Author bookTypeSearch
     * @Description 根据图书类型名称搜索
     * @Date 18:40 2021/1/13
     * @Param bookPage
     * @return java.util.List<com.bean.BookType>
     */
    public List<BookType> bookTypeSearch(BookPage bookPage) {
        SqlSession session = myBatisUtils.getSqlSession();
        String sql = "com.resources.bookTypeMapping.bookTypeSearch";
        List<BookType> list = session.selectList(sql,bookPage);
        return list;
    }

    /*
     * @Author bookTypeCount
     * @Description 返回所有图形类型的数量
     * @Date 18:42 2021/1/13
     * @Param
     * @return int
     */
    public int bookTypeCount() {
        SqlSession session = myBatisUtils.getSqlSession();
        String sql = "com.resources.bookTypeMapping.bookTypeCount";
        int a = session.selectOne(sql);
        return a;
    }

    /*
     * @Author bookTypeSearchCount
     * @Description 根据图形类型的名称查询数量
     * @Date 18:43 2021/1/13
     * @Param name
     * @return int
     */
    public int bookTypeSearchCount(String name) {
        SqlSession session = myBatisUtils.getSqlSession();
        String sql = "com.resources.bookTypeMapping.bookTypeSearchCount";
        int a = session.selectOne(sql,name);
        return a;
    }

    /*
     * @Author addBookType
     * @Description 添加图形类型
     * @Date 18:48 2021/1/13
     * @Param bookType
     * @return int
     */
    public int addBookType(BookType bookType) {
        SqlSession session = myBatisUtils.getSqlSession();
        String sql = "com.resources.bookTypeMapping.addBookType";
        int a = session.insert(sql,bookType);
        session.commit();
        return a;
    }

    /*
     * @Author updateBookType
     * @Description 修改图形类型信息
     * @Date 19:16 2021/1/13
     * @Param bookType
     * @return int
     */
    public int updateBookType(BookType bookType) {
        SqlSession session = myBatisUtils.getSqlSession();
        String sql = "com.resources.bookTypeMapping.updateBookType";
        int a = session.update(sql,bookType);
        session.commit();
        return a;
    }

    /*
     * @Author deleteBookType
     * @Description 删除图形类型
     * @Date 19:19 2021/1/13
     * @Param bId
     * @return int
     */
    public int deleteBookType(int bId) {
        SqlSession session = myBatisUtils.getSqlSession();
        String sql = "com.resources.bookTypeMapping.deleteBookType";
        int a = session.delete(sql,bId);
        session.commit();
        return a;
    }
}
